# def calcSum(beg, end):
#     sum = 0
#     for i in range(beg, end + 1):
#         sum += i
#     return sum
#
#
# print(calcSum(1, 100))

# def get_point():
#     x = 10; y = 20
#     return x, y
#
#
# _, y = get_point()
# print(y)

# x = 20
#
# def test1():
#     x = 10
#     print(f'x = {x}')
#
# def test2():
#     global x
#     x = 30
#     print(f'x = {x}')
#
# test1()
# test2()
# print(f'x = {x}')

# #函数递归求阶层
# def factor(n):
#     if n == 1:
#         return 1
#     return n * factor(n - 1)
# print(factor(5))


# def test(x, y, debug = False):
#     result = x + y
#     if debug:
#         print(result)
#     return result
#
# test(3, 4)
# test(3, 4, True)

# def add(x, y):
#     print(f'x = {x}, y = {y}')
#     return x + y
#
# add(10, 20)#位置参数，10传给x，20传给y
#
# add(x = 10, y = 20)#关键字参数
# add(y = 10, x = 20)#关键字参数

# def add(i, j, k, l):
#     return i + j + k + l
#
# #正确的混用
# add(10, 20, k = 30, l = 40)
# add(10, k = 20, l = 30, j = 40)

#错误的混用
#add(10, 20, j = 30, l = 40)#参数j同时用两种方式传参了
#add(i = 10, j = 20, 30, 40)#关键字传参在前，顺序传参在后

# alist = []
# alist = list()
# print(type(alist))
# print(alist)
# alist = [1, 2, 3, True, 'haha']
# print(alist)
# alist[0] = 100
# print(alist)

# alist = [1, 2, 3]
# # print(alist[100])#抛异常
# print(alist[len(alist) - 1])
# print(alist[-1])

# alist = [1, 2, 3, 4, 5, 6]
# print(alist[ : ])
# print(alist[ : -1])
# print(alist[1 : 2])
# print(alist[ : -2 : 2])
# print(alist[ : : -1])#因为步长是-1，所以等价于alist[5 : : -1]
# print(alist[ : : 1])#因为步长是1，所以等价于alist[0 : 6 : 1]
# print(alist[0 : 5 : -1])

# for i in range(1, 10, -2):
#     print(i)
# print('-------------------')
# for i in range(10, 1, -2):
#     print(i)

# alist = [1, 2, 3, 4]
# alist.append('hello')
# print(alist)
# alist.insert(1, True)
# print(alist)
# print('----------------------')
# print(1 in alist)
# print(True in alist)
# print(10 in alist)
# print(1 not in alist)
# print('----------------------')
#print(alist.index(1))
#print(alist.index(10))#抛异常


# alist = [1, 2, 3, 4, 5, 6, 7, 8]
# print(alist)
# alist.pop()
# print(alist)
# alist.pop(0)
# print(alist)
# alist.remove(2)
# print(alist)

# a = [1, 2, 3]
# b = [4, 5, 6]
# print(a + b)
# print(a)
# print(b)
# print(type(a.extend(b)))#extend没有返回值
# print(a)
# print(b)

# atuple1 = ()
# atuple2 = tuple()
# print(atuple1)
# print(atuple2)
#
# def test():
#     x = 2; y = 3
#     return x, y
# print(type(test()))

# d = dict()
# e = {}
# #当字典中有重复的键时，Python不会报错，而是会用后面的值覆盖前面的值。
# f = {'id':1, 'name':'dongdong', 1:100, (1, 2):[1,2], (1, 2):'haha'}
# print(type(d))
# print(type(e))
# print(type(f))
# print(f)
# print('id' in f)
# print('id' not in f)
# print(100 in f)

# f = {'id':1, 'name':'dongdong', 1:100, (1, 2):[1,2], (1, 2):'haha'}
# print(f[(1, 2)])
# f[100] = 1
# print(f)
# f[100] = 2
# print(f)
# f.pop(100)
# print(f)
# print('--------------------------')
# for i in f:
#     print(i, f[i])
# print(f.keys())
# print(f.values())
# tmp = f.items()
# print("-------------------------")
# print(tmp)
# for key, value in tmp:
#     print(key, value)

# f = {'id':1, 'name':'dongdong', 1:100, (1, 2):[1,2], (1, 2):'haha'}
# for i in list(f.items()):
#     print(type(i), i)
# print('---------------------------------------------------------')
# for key, value in f.items():
#     print(key, value)
# print('---------------------------------------------------------')
# for key in f:
#     print(key, f[key])

# print(hash(0))
# print(hash(3.14))
# print(hash('hello'))
# print(hash(True))
# print(hash(())) # ( ) 是一个空的元组

# f = open('test.txt', 'w')#默认在当前工程路径下面打开test.txt
# f.write('hello')
# f.close()
# f = open('test.txt', 'a')
# f.write(' world')
# f.close()
# f = open('test.txt', 'r')
# result = f.read(100)
# print(result)
# f.close()

# f = open('test.txt', 'r',encoding = 'utf8')
# for line in f:
#     print(line, end = '')
# print('\n------------------------------------')
# #"文件对象在读取操作后会维护一个内部的位置指针。
# # 当使用迭代方式（如 for line in f）读取整个文件后，
# # 该指针已到达文件末尾。此时再进行 readlines() 等读取操作，
# # 由于没有更多内容可读，会返回空结果。"
# lines = f.readlines()
# print(lines)
# f.close()

#上下文管理器
with open('test.txt', 'r', encoding='utf8') as f:
    lines = f.readlines()
    print(lines)
